package com.jt.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component  //将对象交给spring容器管理
@Aspect  //标识是一个切面
public class CacheAop {

    /**
     * aop=切入点表达式+通知方法
     *
     * 拦截需求:
     *  1.要求拦截itemCatServiceImpl的bean
     *  2.拦截com.jt.service下的所有类
     *  3.拦截com.jt.service下的所有类以及方法
     *  @Pointcut("execution(int com.jt.service..*.add*(String))")
     */
    //@Pointcut(value = "bean(itemCatServiceImpl)")
   /* @Pointcut(value = "within(com.jt.service..*)")
    //拦截com.jt.service下的所有类的所有方法的任意参数类型 任意返回值
    //@Pointcut("execution(* com.jt.service..*.*(..))")
  // @Pointcut("@annotation(com.jt.annoaction.CacheFind)")
    public void poincut(){}

    //定义前置通知
    @Before("poincut()")
    public void before(){
        System.out.println("我是前置通知");
    }*/
   /* @Before("@annotation(com.jt.anno.CacheFind)")
    public void before(JoinPoint joinPoint) throws NoSuchMethodException {
        Object obj = joinPoint.getTarget();//获取目标对象
        Class cls = joinPoint.getTarget().getClass();//获取目标对象的类型
        Object[] arg = joinPoint.getArgs();//获取方法参数
        String className = joinPoint.getSignature().getDeclaringTypeName();//获取目标对象的名称
        Class tagerClass = joinPoint.getSignature().getDeclaringType();//获取目标对象的类型
        String methodName = joinPoint.getSignature().getName();//获取目标方法的名称
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        Method method = cls.getDeclaredMethod(methodName,methodSignature.getParameterTypes());//获取方法的对象
        System.out.println(obj);
        System.out.println(cls);
        System.out.println(arg);
        System.out.println(className);
        System.out.println(tagerClass);
        System.out.println(methodName);
        System.out.println(method);
    }
*/
}
